package com.qfedu.vhr.controller.sys;

import com.qfedu.vhr.common.RespBean;
import com.qfedu.vhr.framework.entity.Role;
import com.qfedu.vhr.framework.entity.vo.MenuVO;
import com.qfedu.vhr.framework.service.IMenuService;
import com.qfedu.vhr.framework.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author baize
 * @date 2023/1/12
 * @site www.qfedu.com
 */
@RestController
@RequestMapping("/system/basic/permission")
public class PermissionController {

    @Autowired
    IRoleService roleService;
    @Autowired
    IMenuService menuService;

    @GetMapping("/roles")
    public List<Role> getAllRoles() {
        return roleService.list();
    }

    @GetMapping("/menus")
    public List<MenuVO> getAllMenus() {
        return menuService.getAllMenus();
    }

    @GetMapping("/menuid/{rid}")
    public List<Integer> getSelectedMenuIdByRoleId(@PathVariable Integer rid) {
        return menuService.getSelectedMenuIdByRoleId(rid);
    }

    @PutMapping("/")
    public RespBean updateMenuRole(Integer rid, Integer[] mids) {
        return menuService.updateMenuRole(rid, mids);
    }

}
